
#include "keith.h"

Keith::Keith() : Player()
{
    health = 400;
    damage = 26;
    animation_speed=0;

    //all stuff for Character animation
    character_image.load("grafx/level2/keith.png");
    sword.load("grafx/level2/keithsword.png");
    heart.load("grafx/health.png");

    //swordsound.load("sounds/level2/sword.wav");
    moving_right = true;
    frame=0;

    sprite_info.w = 65;
    sprite_info.h = 80;

    swordtimer = 0;
}

Keith::~Keith()
{

}
/*
void Keith::setHealth(int set_health )
{
    health = set_health;
}

*/
int Keith::action(int x, int y)
{
    int value =100;
    if(attacking)
        value=1;
    if(attacking && moving_right)
        value=0;

    Draw(x, y);

    return value;
}

void Keith::Draw( int x, int y)
{
    sprite_info.x = x;
	sprite_info.y = y;

    if(attacking)
    {
        swordtimer = 5;
        attacking = false;
       // swordsound.play();
    }

    if(swordtimer >0)
    {
        if(moving_right)
        {
        sword.drawAnim(x, y, 110, sprite_info.h, 0, 0);
        }
        else
            sword.drawAnim(x-45, y, 110, sprite_info.h, 110, 0);

        swordtimer--;
    }
    else
    {
        if(moving_right)
        {
            if (jumped)
                character_image.drawAnim(x, y, sprite_info.w, sprite_info.h, 65, 0);
            else
                character_image.drawAnim(x, y, sprite_info.w, sprite_info.h, frame, 0); // problem line !!!!!!
        }
        else
        {
            if(jumped)
                character_image.drawAnim(x, y, sprite_info.w, sprite_info.h, 65, 80);
            else
                character_image.drawAnim(x, y, sprite_info.w, sprite_info.h, frame, 80);
        }

    }
    DrawHealth();
}

void Keith::Move_frame()
{
    if(animation_speed == 3)
    {
        if (frame < 195)
        {
            frame=frame+65;
        }
        else
            frame=0;

        animation_speed = 0;
    }
    else
        animation_speed++;

}

void Keith::DrawHealth()
{
    int total_hearts =6;

    int red = health/100;
    int half_red = health%100;

    int count = 0;
//Laydown black hearts
    for(int i=1; i<=6; i++)
    {
        heart.drawAnim(25+count, 25, 30, 30, 30, 0);
        count+=30;
    }
    count=0;
//Draw red hearts over the black
    for(int i=1; i<=red; i++)
    {
        heart.drawAnim(25+count, 25, 30, 30, 0, 0);
        count+=30;
    }
    total_hearts -=red;
//Draw half hearts

    if(half_red >= 50 )
        heart.drawAnim(25+count, 25, 30, 30, 60, 0);
    if(health>0 && health<50)
        heart.drawAnim(25+count, 25, 30, 30, 60, 0);

}

